package com.yanxi.controller;

import com.yanxi.anno.Log;
import com.yanxi.pojo.Clazz;
import com.yanxi.pojo.EmpQueryParam;
import com.yanxi.pojo.PageResult;
import com.yanxi.pojo.Result;
import com.yanxi.service.ClazzService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/clazzs")
@RestController
public class ClazzController {
    public static final Logger log = LoggerFactory.getLogger(ClazzController .class);
    @Autowired
    private ClazzService clazzService;
    //分页查询所有班级
    @GetMapping
    public Result pageClazz(EmpQueryParam empQueryParam){
        log.info("分页查询所有班级，参数：{} ",empQueryParam);
        PageResult<Clazz> pageResult = clazzService.pageClazz(empQueryParam);
        return Result.success(pageResult);
    }

    @Log
    //删除班级
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        log.info("删除班级，id：{}", id);
        clazzService.delete(id);
        return Result.success();
    }

    @Log
    //新增班级
    @PostMapping
    public Result save(@RequestBody Clazz clazz){
        log.info("新增班级，班级信息：{}",clazz);
        clazzService.save(clazz);
        return Result.success();
    }
    //根据id查询班级
    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id){
        log.info("根据id查询班级，id：{}",id);
        Clazz clazz = clazzService.findById(id);
        return Result.success(clazz);
    }

    @Log
    //修改班级
    @PutMapping
    public Result update(@RequestBody Clazz clazz){
        log.info("修改班级，班级信息：{}",clazz);
        clazzService.update(clazz);
        return Result.success();
    }

    //查询所有班级
    @GetMapping("/list")
    public Result listAll(){
        log.info("查询所有班级");
        List<Clazz> clazzList = clazzService.listAll();
        return Result.success(clazzList);
    }

}
